package com.dl.mall.service.user.impl;

import com.dl.mall.mapper.AddressMapper;
import com.dl.mall.entity.user.Address;
import com.dl.mall.service.user.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author DL
 * @create 2022-03-21 20:18
 */
@Service
@Transactional
public class AddressServiceImpl implements AddressService {

    @Resource
    AddressMapper addressMapper;

    /**
     * 增加地址
     * @param address 地址
     * @return 行数
     */
    @Override
    public int addAddress(Address address) {
        return addressMapper.insertAddress(address);
    }

    /**
     * 根据 地址id 更新地址
     * @param userId 用户id
     * @param addressId 地址id
     * @return 行数
     */
    @Override
    public int setDefaultAddress(String userId, String addressId) {
        return addressMapper.setDefaultAddress(userId, addressId);
    }

    /**
     * 根据 地址id 更新地址
     * @param address 地址
     * @return 行数
     */
    @Override
    public int modifyAddress(Address address) {
        return addressMapper.updateAddress(address);
    }

    /**
     * 获取默认地址
     * @param userId 用户id
     * @return 地址
     */
    @Override
    public int getTotalAddress(String userId) {
        return addressMapper.getTotalAddress(userId);
    }

    /**
     * 根据 地址id 查询地址信息
     * @param addressId 用户id
     * @return 地址
     */
    @Override
    public Address getAddressById(String addressId) {
        return addressMapper.queryAddressById(addressId);
    }

    /**
     * 根据 用户id 获取该用户默认地址
     * @param userId 用户id
     * @return 地址
     */
    @Override
    public Address getDefaultAddress(String userId) {
        return addressMapper.queryDefaultAddress(userId);
    }

    /**
     * 根据 用户id 获取该用户所有地址
     * @param userId 用户id
     * @return 地址
     */
    @Override
    public List<Address> getAllAddress(String userId) {
        return addressMapper.queryAllAddress(userId);
    }
}
